package com.example.demodb.repository;

import com.example.demodb.entity.Song;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Collection;
import java.util.List;

public interface ISongRepository extends JpaRepository<Song, String> {

//    @Modifying
//    @Query("update TodoItem todo "
//            +"set todo.isDone=?2 "
//            +"where todo.id=?1 "
//    )
//    public void update(Long id, Boolean isDone);

    @Transactional
    void deleteById(String id);

    Song findSongById(String id);

    Song findFirstByTitle(String songTitle);

    @Query(value = "select * from song order by rand() limit ?1 ", nativeQuery = true)
    List<Song> randomGenerate(Integer num);

    @Query(value = "select * from song where style=?1 limit 10 ", nativeQuery = true)
    List<Song> findSongsByStyle(String style);

    List<Song> findAllByArtistContains(String search);

    List<Song> findAllByTitleContains(String search);
}
